package com.superhelper.deliver.task.impl;

import org.springframework.context.ApplicationContext;

import com.superhelper.common.domain.DeliverRecord;
import com.superhelper.common.domain.Task;
import com.superhelper.common.mapper.DeliverRecordMapper;
import com.superhelper.common.mapper.TaskMapper;
import com.superhelper.deliver.service.DeliverService;
import com.superhelper.deliver.task.AbstractTaskRunnable;

public class DeliverRecordTask extends AbstractTaskRunnable {

    public DeliverRecordTask(ApplicationContext appContext, TaskMapper taskMapper, Task task) {
        super(appContext, taskMapper, task);
    }

    @Override
    protected boolean execute() {
        log.info("run start taskId:{}", task.getId());
        DeliverRecordMapper recordMapper = appContext.getBean(DeliverRecordMapper.class);
        DeliverRecord dr = recordMapper.getById(Long.valueOf(task.getObjId()));
        if (dr == null) {
            log.info("not found deliverRecord taskId:{}", task.getId());
            return true;
        }
        DeliverService deliverService = appContext.getBean(DeliverService.class);
        return deliverService.deliver(dr);
    }

}
